package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Activities;
import com.ww.sound_emission.service.ActivitiesService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivitiesService activityService;

    // 获取所有活动
    @GetMapping
    public Result<List<Activities>> getAllActivities() {
        List<Activities> activities = activityService.list();
        return Result.success(activities);
    }

    // 添加活动
    @PostMapping
    public Result<String> addActivity(@RequestBody Activities activity) {
        activityService.save(activity);
        return Result.success("活动添加成功");
    }

    // 删除活动
    @DeleteMapping("/{id}")
    public Result<String> deleteActivity(@PathVariable Long id) {
        activityService.removeById(id);
        return Result.success("活动删除成功");
    }
}